import re
from pkg.driver import all_command
from pkg.nlp import user_trans


def translate(txt):
    txt=txt[0]
    print(txt)
    pt=re.compile('.*建.*数据库表(.+)')
    m=pt.match(txt)
    if m:
        print(m.group(1))
        all_command.create_table(m.group(1))
        return
    pt = re.compile('(关闭)|(退出).*')
    m = pt.match(txt)
    if m:
        all_command.exit_system()
        return
    pt = re.compile('执行数据库语句(.*)')
    m = pt.match(txt)
    if m:
        all_command.exec_sql(m.group(1))
        return
    pt = re.compile('.*数据库表(.*)插入数据.*')
    m = pt.match(txt)
    if m:
        all_command.insert_sql(m.group(1))
        return
    pt = re.compile('插入数据.*')
    m = pt.match(txt)
    if m:
        all_command.insert_sql('')
        return
    pt = re.compile('查.*数据库表(.*)')
    m = pt.match(txt)
    if m:
        all_command.select_all(m.group(1))
        return
    pt = re.compile('.*音乐播放器.*')
    m = pt.match(txt)
    if m:
        all_command.music()
        return

    pt = re.compile('播放.*')
    m = pt.match(txt)
    if m:
        all_command.play()
        return

    if not user_trans.user_trans(txt):
            all_command.default_act(txt)



